package com.eric.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.eric.domain.po.MaterialInPhoto;
import com.eric.mapper.MaterialInPhotoMapper;
import com.eric.service.IMaterialInPhotoService;
import com.eric.utils.ServerBASEURL;
import com.github.yulichang.base.MPJBaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * material_in图片附件表格 服务实现类
 * </p>
 *
 * @author 新哥
 * @since 2024-04-17
 */
@Service
public class MaterialInPhotoServiceImpl extends MPJBaseServiceImpl<MaterialInPhotoMapper, MaterialInPhoto> implements IMaterialInPhotoService {

    @Override
    @Transactional
    public void deleteByPhotoUrlList(List<String> photoUrlList) {
        List<MaterialInPhoto>list= new ArrayList<>();
//        遍历photoUrlList
        for (String photoUrl : photoUrlList) {
//      去除了ServerBASEURL.BASEURL的部分，得到了新的photoUrl
            String newPhotoUrl = StrUtil.removePrefix(photoUrl, ServerBASEURL.BASEURL);
            MaterialInPhoto materialInPhoto = lambdaQuery()
                    .eq(MaterialInPhoto::getPhotoUrl, newPhotoUrl)
                    .one();
            if (!BeanUtil.isEmpty(materialInPhoto)) {
                list.add(materialInPhoto);
            }
        }
        if (!list.isEmpty()) {
            removeByIds(list);
        }
    }
}
